import {findAll,findWaiterShou,saveOrUpdate,detailsShou,findWaiterById} from '@/api/waiter.js'
import { Notification } from 'element-ui';
export default {
    namespaced:true,
    state:{
        //后台总数据
        totalData:{},
        DetailsShou:[],
        WaiterOrder:[]
    },
    getters:{
        //总条数
        total:state=>state.totalData.total,
        waiterData:state=>state.totalData.list,
    },
    mutations:{
        changeTotalData(state,data){
            state.totalData=data
        },
        changeDetailShou(state,data){
            state.DetailsShou=data
        },
        changeWaiterData(state,data){
            state.WaiterOrder=data
        }
    },
    actions:{
        findWaiterById({commit},payload){
            findWaiterById(payload).then(res=>{
                commit("changeWaiterData",res.data)
            })
        },
        detailsShou({commit},payload){
            detailsShou(payload).then(res=>{
                commit("changeDetailShou",res.data)
            })
        },
        findAll({commit},payload){
            findAll(payload).then(res=>{
                commit('changeTotalData',res.data)
            })
        },
        findWaiterShou({commit},payload){
            findWaiterShou(payload).then(res=>{
                commit('changeTotalData',res.data)
            })
        },
        async saveOrUpdate({dispatch},payload){
            //接受数据，发送请求 ，提示用户保存成功，处理page,分发findAll动作
            let res=await saveOrUpdate(payload.form);
            if(res.status===200){
              Notification({
                type:'success',
                title:'成功',
                message:'保存成功'
              })
              //查找数据 (区分是新增查找还是修改查找 如果是新增查找 找最后一页，如果是修改查找，找当前页)
              dispatch('findAll',payload.queryParams);
            }else{
              Notification({
                type:'error',
                title:'失败',
                message:'保存失败'
              })
            }
          },

    }
}